package ;

import easelhx.display.Container;
import easelhx.display.Shape;
import easelhx.display.Stage;
import easelhx.display.Text;
import easelhx.events.MouseEvent;
import js.HTMLCanvasElement;
import js.Lib;

/**
 * ...
 * @author 
 */

class DoubleClickTestExample
{
	
	private var canvas:HTMLCanvasElement;
	private var stage:Stage;

	public function new() 
	{
		canvas = cast Lib.document.getElementById("testCanvas");
		stage =  new Stage(canvas);
	}
	
	public function run():Void 
	{
		// Create a new Text object and a rectangle Shape object, and position them inside a container:
		var container:Container = new Container();
		container.x = 100;
		container.y = 80;
		
		var target = new Shape();
		target.graphics.beginFill("#F00").drawRect(-10,-10,300,60).beginFill("#FFF");
		container.addChild(target);

		var txt = new Text("Double Click Me!", "36px Arial", "#FFF");
		txt.textBaseline = "top";
		container.addChild(txt);

		stage.addChild(container);
		
		Reflect.setField(container, MouseEvent.onDoubleClick, onDoubleClick);
		
		//untyped __js__ ("container.onDoubleClick = function(evt) { alert('teste'); };");
		
		stage.update();
	}
	
	private function onDoubleClick() 
	{
		Lib.alert("Double Clicked the container object");
	}
	
}